package concurrent1;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

public class DeamonThread1 {

    public static void main(String[] args) throws InterruptedException {
        Runtime.getRuntime().addShutdownHook(new Thread(()->{
            System.out.println("Shutting down");
        }));

        Thread thread = new Thread(() -> {
            while (true) {
                try {
                    TimeUnit.SECONDS.sleep(1);
                    System.out.printf("当前线程：%s,正在运行\n", Thread.currentThread().getName());
                } catch (InterruptedException e) {
                    System.out.printf("当前线程：%s，休眠异常：%s\n", Thread.currentThread().getName(), e);
                }
            }

        }, "子线程1");

        Runtime runtime = Runtime.getRuntime();
        System.out.println( runtime.totalMemory());

        thread.setDaemon(true);
        thread.start();
        TimeUnit.SECONDS.sleep(2);
        System.out.println("朱线程结束");
    }
}
